// 引入封装好的axios
import {reqCategoryList, reqGetBannerList, reqGetFloorList} from '@/api'

// home模块小仓库
const state = {
    // 三级菜单的数据
    categoryList: [],
    // banner轮播图的数据
    bannerList: [],
    // floor数据
    floorList: []
}
const actions = {
    // async和await一起使用，等待异步请求返回的结果
    async categoryList(context) {
        // 发送请求获取结果
        const result = await reqCategoryList();
        if (result.code === 200) {
            // actions提交到mutations进行数据的改写
            context.commit('CATEGORYLIST', result.data)
        }
    },
    // 发送请求到mock获取banner模拟数据
    async getBannerList(context) {
        const result = await reqGetBannerList();
        if (result.code === 200) {
            context.commit('GETBANNERLIST', result.data)
        }
    },
    // 发送请求到mock获取floor模拟数据
    async getFloorList(context) {
        const result = await reqGetFloorList();
        if (result.code === 200) {
            context.commit('GETFLOORLIST', result.data)
        }
    }
}
const mutations = {
    CATEGORYLIST(state, categoryList) {
        state.categoryList = categoryList
    },
    GETBANNERLIST(state, bannerList) {
        state.bannerList = bannerList
    },
    GETFLOORLIST(state, floorList) {
        state.floorList = floorList
    }
}
const getters = {}

export default {
    state,
    actions,
    mutations,
    getters
}